package com.effectiv.gooruda.rest.api.controller;

import java.util.Date;
import java.util.List;

import javax.validation.Valid;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.effectiv.gooruda.rest.api.domain.Log;
import com.effectiv.gooruda.rest.api.operation.LogOperations;

@Deprecated
@Controller
@RequestMapping("/api/log")
public class LogContoller implements LogOperations, Sample {

	@Autowired
	@Qualifier("logServiceImpl")
	private LogOperations operations;

	// yyyy-MM-dd
	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#findBetween(java.util.Date, java.util.Date, int, int)
	 */
	@Override
	@RequestMapping(value = "/findbetween/{start}/{end}", method = RequestMethod.GET)
	public @ResponseBody
	List<Log> findBetween(
			@PathVariable @DateTimeFormat(iso = ISO.DATE) Date start,
			@PathVariable @DateTimeFormat(iso = ISO.DATE) Date end,
			@RequestParam(value = "pageNo", required = false, defaultValue = "0") int pageNo,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {

		return operations.findBetween(start, end, pageNo, pageSize);
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#findByLogText(java.lang.String, int, int)
	 */
	@Override
	@RequestMapping(value = "/findbylogtext/{text}", method = RequestMethod.GET)
	public @ResponseBody
	List<Log> findByLogText(
			@PathVariable String text,
			@RequestParam(value = "pageNo", required = false, defaultValue = "0") int pageNo,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {

		return operations.findByLogText(text, pageNo, pageSize);
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#save(com.effectiv.gooruda.rest.api.domain.Log)
	 */
	@Override
	@RequestMapping(method = RequestMethod.POST)
	@ResponseStatus(HttpStatus.CREATED)
	public @ResponseBody
	Log save(@Valid @RequestBody Log l) {
		Log log = operations.save(l);
		return log;
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#findByType(java.lang.String, int, int)
	 */
	@Override
	@RequestMapping(value = "/findbytype/{type}", method = RequestMethod.GET)
	public @ResponseBody
	List<Log> findByType(
			@PathVariable String type,
			@RequestParam(value = "pageNo", required = false, defaultValue = "0") int pageNo,
			@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {

		return operations.findByType(type, pageNo, pageSize);
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#countByType(java.lang.String)
	 */
	@Override
	@RequestMapping(value = "/countbytype/{type}", method = RequestMethod.GET)
	public @ResponseBody
	long countByType(@PathVariable String type) {
		return operations.countByType(type);
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#countByText(java.lang.String)
	 */
	@Override
	@RequestMapping(value = "/countbytext/{text}", method = RequestMethod.GET)
	public @ResponseBody
	long countByText(@PathVariable String text) {
		return operations.countByText(text);
	}

	/* (non-Javadoc)
	 * @see com.effectiv.gooruda.rest.api.controller.Sample#countByDateRange(java.util.Date, java.util.Date)
	 */
	@Override
	@RequestMapping(value = "/countbydaterange/{start}/{end}", method = RequestMethod.GET)
	public @ResponseBody
	long countByDateRange(

	@PathVariable @DateTimeFormat(iso = ISO.DATE) Date start,
			@PathVariable @DateTimeFormat(iso = ISO.DATE) Date end) {
		return operations.countByDateRange(start, end);
	}
}
